package ThreadDemo;

import static java.lang.Thread.sleep;

public class ThreadDemo11 {
    public static void main(String[] args) throws InterruptedException {
        Thread t1=new Thread(){
            @Override
            public void run() {
                for(int i=0;i<10;i++){
                    System.out.println("我是线程1");
                    try {
                        sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        Thread t2=new Thread(){
            @Override
            public void run() {
                for(int i=0;i<10;i++){
                    System.out.println("我是线程2");
                    try {
                        sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        for(int i=0;i<10;i++){
            System.out.println("我是主线程");
            try {
                sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
